import { getControllers, regControllers } from '../utils/tools.js'
import Router from 'koa-router'
import bodyParser from 'koa-bodyparser'
import cors from '@koa/cors'

let router = new Router()

export let route = function (app) {
  // 解决跨域问题
  app.use(cors())
  // 获取文件路径
  let controllerFile = getControllers()

  app.use(bodyParser())
  // 注册路由
  regControllers(router, controllerFile)
  app.use(router.routes())
}
